package com.chinasoft.controller;

import com.chinasoft.domain.Student;
import com.chinasoft.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private IStudentService studentService;

    /**
     * 查询所有
     */
    @ResponseBody
    @RequestMapping("/list")
    public List<Student> findAll(){
        List<Student> students = studentService.findAll();
        return students;
    }

    /**
     * 查询单个
     */
    @ResponseBody
    @RequestMapping("/{id}")
    public Student findById(@PathVariable("id") Long id){
        Student student = studentService.findById(id);
        return student;
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    public void deleteById(@PathVariable("id") Long id){
        studentService.delete(id);
    }

}
